package cn.wolfcode.shop.cloud.mq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(
        consumerGroup = MQConstans.CREATE_ORDER_SUCCESS_GROUP,
        topic = MQConstans.CREATE_ORDER,
        selectorExpression = MQConstans.CREATE_ORDER_SUCCESS_TAG

)
public class OrderSuccessMQListener implements RocketMQListener<Map> {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void onMessage(Map map) {
        System.out.println("进入成功消息");
        //成功以后发送延时信息
        //并不是在成功的队列中直接去检查订单是否有支付
        MessageBuilder<Map> builder = MessageBuilder.withPayload(map);
        rocketMQTemplate.syncSend(MQConstans.CREATE_ORDER_DELAY_DEST, builder.build(),5000 , 3);

    }
}
